package com.ruoyi.project.tool.swagger.WorkerController;

import com.ruoyi.common.constant.Constants;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.framework.aspectj.lang.annotation.Ide;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.annotation.SignatureValidation;
import com.ruoyi.framework.aspectj.lang.enums.OperatorType;
import com.ruoyi.framework.interceptor.annotation.RepeatSubmit;
import com.ruoyi.framework.security.service.SysLoginService;
import com.ruoyi.framework.security.service.TokenService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.project.system.domain.vo.LoginVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/mobileWorker/")
@Api(tags = "工人端app登录",description = "工人端app登录")
public class WorkerUserController extends BaseController {

    @Autowired
    private TokenService tokenService;


    @Autowired
    private SysLoginService loginService;

    @ApiOperation("获取工人详细信息")
    @GetMapping("/getInfo")
    public AjaxResult getUser() {
        return AjaxResult.success(SecurityUtils.getLoginUser().getUser());
    }


    @PostMapping(value = "/loginMobile")
    @Log(title = "工人端登录", operatorType = OperatorType.MOBILE)
    @Ide
    @RepeatSubmit
    @SignatureValidation
    @ApiOperation("工人端手机号或者用户名登录")
    public AjaxResult login(@RequestBody LoginVo vo) {
        Object token = loginService.loginWorker(vo.getUsername(), vo.getPassword());
        return AjaxResult.success(token);
    }

}
